package com.typeinfo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.net.mindview.util.Coffee;
import com.net.mindview.util.CoffeeGenerator;
import com.net.mindview.util.Generator;

public class Fill2Test {
    public static void main(String[] args) {
		List<Coffee> carrier=new ArrayList<Coffee>();
		Fill2.fill(new AddableCollectionAdapter<Coffee>(carrier), Coffee.class, 3);
		Fill2.fill(new AddableCollectionAdapter<Coffee>(carrier), new CoffeeGenerator(10), 5);
		for(Coffee c:carrier){
			System.out.println(c);
		}
	}
}
class Fill2{
	public static<T> void fill(Addable<T> addable,Class<? extends T> ClassToken,int size){
		for(int i=0;i<size;i++){
			try {
				addable.add(ClassToken.newInstance());
			} catch (InstantiationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	public static <T> void fill(Addable<T> addable,Generator<T> generator,int size){
		for(int i=0;i<size;i++){
			addable.add(generator.next());
		}
	}
}
class AddableCollectionAdapter<T> implements Addable<T>{
    private Collection<T> c;
    public AddableCollectionAdapter(Collection<T> c){
    	this.c=c;
    }
	@Override
	public void add(T t) {
		// TODO Auto-generated method stub
		c.add(t);
	}
	
}
class Adapter{
	public static <T> Addable<T> collectionAdapter(Collection<T> c){
		return new AddableCollectionAdapter<T>(c);
	}
}

class AddableSimpleQueue<T> extends SimpleQueue{
	
}
